﻿using Sharp.Portal.Mvc.Form;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// ReSharper disable once CheckNamespace
namespace Sharp.Portal.Mvc
{
    /// <summary>
    /// 自定义字段
    /// </summary>
    public class CustomFieldAttribute : System.Attribute
    {
        /// <summary>
        /// 自定义字段
        /// </summary>
        /// <param name="fieldType"></param>
        public CustomFieldAttribute(FieldType fieldType)
        {
            FieldType = fieldType;
            if (fieldType == FieldType.OrgTreeList)
            {
                DisplayField = "title";
                ValueField = "id";
            }
        }
        /// <summary>
        /// 自定义字段
        /// </summary>
        /// <param name="fieldType"></param>
        /// <param name="dataSourceName"></param>
        public CustomFieldAttribute(FieldType fieldType, string dataSourceName)
        {
            FieldType = fieldType;
            DataSourceName = dataSourceName;
            if (fieldType == FieldType.OrgTreeList)
            {
                DisplayField = "title";
                ValueField = "id";
            }
        }
        /// <summary>
        /// 自定义字段
        /// </summary>
        /// <param name="fieldType"></param>
        /// <param name="displayField"></param>
        /// <param name="valueField"></param>
        /// <param name="dataSourceName">数据源的名称</param>
        public CustomFieldAttribute(FieldType fieldType, string displayField, string valueField, string dataSourceName)
        {
            FieldType = fieldType;
            DisplayField = displayField;
            ValueField = valueField;
            DataSourceName = dataSourceName;
        }
        public FieldType FieldType { get; set; }
        /// <summary>
        /// 显示字段
        /// </summary>
        /// <remarks>如果不赋值，会自动给予字段的名称</remarks>
        public string DisplayField { get; set; }
        /// <summary>
        /// 值字段
        /// </summary>
        /// <remarks>如果不赋值，会自动给予字段的名称</remarks>
        public string ValueField { get; set; }
        /// <summary>
        /// 数据源的名称
        /// </summary>
        public string DataSourceName { get; set; }

        public object Model { get; set; }
    }
}
